package cn.b.sky.mes.andon.controller;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.b.sky.mes.andon.model.AndonRun;
import cn.b.sky.mes.andon.model.AndonType;
import cn.b.sky.mes.andon.model.condition.AndonRunCondition;
import cn.b.sky.mes.andon.service.AndonRunService;
import cn.b.sky.mes.andon.service.AndonTypeService;
import cn.b.sky.user.SecurityContextUtil;
import cn.b.sky.user.controller.SecurityController;
import cn.b.sky.mes.cm.enums.ECodeEnums;
import cn.b.sky.user.service.ECodeService;
import cn.b.sky.user.service.model.ECode;

/**
 * 
 * <strong>Title : AndonRunController.java<br></strong>
 * <strong>Package : cn.b.sky.mes.andon.controller<br></strong>
 * <strong>Description : </strong>暗灯运转记录控制器<br> 
 * <strong>Create on : 2016-10-17 下午1:36:36<br></strong>
 * <p>
 * @author JinQuan.Fu<br>
 * @version <strong>v1.0.0</strong><br>
 * <br>
 * <strong>修改历史:</strong><br>
 * 修改人|修改日期|修改描述<br>
 * -------------------------------------------<br>
 * <br>
 * <br>
 */
@Controller
@RequestMapping("/andonRun/*")
public class AndonRunController extends SecurityController {
  
  @Resource
  AndonRunService andonRunService;
  
  @Resource
  AndonTypeService andonTypeService;
  
  @Resource
  ECodeService eCodeService;
  
  @RequestMapping("andonRunList")
  public String andonRunList(Model model, @ModelAttribute("condition") AndonRunCondition condition, String navTabId) {
    condition.setSiteCode(getSiteCode());
    if (StringUtils.isBlank(condition.getOrderField())) {
      condition.setOrderField("CreateDateTime");
    }
    List<ECode> ecode = eCodeService.selectECodeList(ECodeEnums.ANDONRUNSTATUS.getCode(),SecurityContextUtil.getLanguageCode());
    List<AndonRun> list = andonRunService.selectAndonRunListByCondition(condition);
    int count = andonRunService.selectandonRunListCountByCondition(condition);
    condition.setData(list);
    condition.setTotalCount(count);
    List<AndonType> andonTypes = andonTypeService.getAllAndonTypes(this.getSiteCode());
    model.addAttribute("andonTypes", andonTypes);
    model.addAttribute("andonRunStatus", ecode);
    model.addAttribute(NAVTABID, navTabId);
    model.addAttribute("page", condition);
    return "andon/andonRun/andonRun_list";
  }
  
}
